package com.epoint.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.epoint.common.Result;
import com.epoint.entity.BorrowInfo;
import com.epoint.service.BorrowInfoService;

/**
 * Servlet implementation class BorrowInfoAddAction
 */
@WebServlet("/borrowinfoaddaction")
public class BorrowInfoAddAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	BorrowInfoService borrowInfoService = new BorrowInfoService();
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public BorrowInfoAddAction() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String data = request.getParameter("data");
		// 将json字符串转为BookInfo对象
		BorrowInfo borrowInfo = JSONObject.parseObject(data,BorrowInfo.class);
		int flag = borrowInfoService.addBorrowInfo(borrowInfo);
		
		String returnCode = Result.returnCode(flag);
		response.getWriter().print(returnCode);
	}

}
